import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/mk_card_container.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class QuestionnaireListPage extends StatefulWidget {
  const QuestionnaireListPage({Key? key}) : super(key: key);

  @override
  State<QuestionnaireListPage> createState() => _QuestionnaireListPageState();
}

class _QuestionnaireListPageState extends State<QuestionnaireListPage> {
  final controller = Get.find<QuestionnaireListController>();
  final state = Get.find<QuestionnaireListController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
        child: Scaffold(
      backgroundColor: Colors.transparent,
      appBar: TDNavBar(
        backgroundColor: Colors.transparent,
        title: '问卷调查',
      ),
      body: Obx(() => ListView.builder(
            itemBuilder: (context, index) {
              return GestureDetector(
                onTap: () {
                  Get.toNamed(RouterName.questionnaireDetail,
                      arguments: {"id": state.list[index].id});
                },
                child: MkCardContainer(
                  padding: EdgeInsets.all(AppTheme.iDefaultPadding),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        state.list[index].title!,
                        style: TextStyle(fontSize: 16),
                      ),
                      Gaps.vGap12,
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            state.list[index].time!,
                            style: TextStyle(fontSize: 12),
                          ),
                          state.list[index].isFinish! ?TDTag(
                            '已完成',
                            size: TDTagSize.small,
                            theme: TDTagTheme.success,
                          ): TDTag(
                            '未完成',
                            size: TDTagSize.small,
                            theme: TDTagTheme.warning,
                          )
                        ],
                      )
                    ],
                  ),
                ),
              );
            },
            itemCount: state.list.length,
          )),
    ));
  }

  @override
  void dispose() {
    Get.delete<QuestionnaireListController>();
    super.dispose();
  }
}
